package com.helloscala.web
package rest

import net.liftweb.http.rest.RestHelper
import net.liftweb.common.{Full, Loggable}
import net.liftweb.http.PlainTextResponse

import com.helloscala.helper.MarkdownHelpers

object DocumentRest extends RestHelper with Loggable {

  serve("api" / "document" prefix {
    case "markdown" :: "parser" :: Nil Post req =>
      try
        req.param("content") map
          (content => PlainTextResponse(MarkdownHelpers.parseToString(content))) or
          Full(PlainTextResponse("param content not found!"))
      catch {
        case e: Exception =>
          Full(PlainTextResponse(e.getLocalizedMessage))
      }

  })

}
